import {
  get
} from "../../untils/db"

Page({
  data: {
    look: false,
    option1: [{
        text: '全部',
        value: 0
      },
      {
        text: '加分',
        value: 1
      },
      {
        text: '扣分',
        value: 2
      },
    ],
    value1: 0,
    pageNum: 1,
    scoreType: 0,
    menu0: [],
    menu1: [],
    menu2: [],
    rows0: [],
    rows1: [],
    rows2: [],
    bottom: false
  },

  change({
    detail
  }) {
    console.log(detail);
    this.setData({
      scoreType: detail
    }, () => {
      console.log(this.data.scoreType);
    })
    this.setData({
      menu0:[],
      menu1:[],
      menu2:[],
    })
    this.onLoad()
  },
  async onLoad() {
    let token = wx.getStorageSync('login')
    let obj = {
      pageNum: this.data.pageNum,
      pageSize: 10,
      scoreType: this.data.scoreType
    }
    let res = await get("/api/integral-logs/findPage", obj, token)
    console.log(res.data.total);
    if (obj.scoreType == 0) {
      this.setData({
        rows0: res.data.total,
        menu0: this.data.menu0.concat(res.data.rows)
      })
    } else if (obj.scoreType == 1) {
      this.setData({
        rows1: res.data.total,
        menu1: this.data.menu1.concat(res.data.rows)
      })
    } else if (obj.scoreType == 2) {
      this.setData({
        rows2: res.data.total,
        menu2: this.data.menu2.concat(res.data.rows)
      })
    }

  },

  onReachBottom() {
    if (this.data.menu0.length < this.data.rows0 | this.data.menu1.length < this.data.rows1 | this.data.menu2.length < this.data.rows2) {
      this.setData({
        pageNum: this.data.pageNum + 1,
        bottom: true
      })
      this.onLoad()
    }

  }
})